package com.bosssoft.boss_exam_db.service.busines.impl;

import com.bosssoft.boss_exam_db.entity.ApplicantExamPaper;
import com.bosssoft.boss_exam_db.mapper.ApplicantExamPaperMapper;
import com.bosssoft.boss_exam_db.model.vo.ApplicantExamPaperVO;
import com.bosssoft.boss_exam_db.service.base.impl.BaseServiceImpl;
import com.bosssoft.boss_exam_db.service.busines.ApplicantExamPaperService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
@Service
@Slf4j
public class
ApplicantExamPaperServiceImpl extends BaseServiceImpl<ApplicantExamPaper> implements ApplicantExamPaperService {

    //注入ApplicantExamPaperMapper
    @Autowired
    private ApplicantExamPaperMapper applicantExamPaperMapper;


    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description 根据考试批次查询考试
     * @Param [examCode]
     * @Return java.util.List<com.bosssoft.boss_exam_db.model.vo.ApplicantExamPaperVO>
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public List<ApplicantExamPaperVO> queryByCondition(String examCode) {
        return applicantExamPaperMapper.queryByExamCode(examCode);
    }

    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description  根据考试ID和试卷ID查询应聘者试卷记录
     * @Param [examId, examPaperId]
     * @Return java.util.List<com.bosssoft.boss_exam_db.entity.ApplicantExamPaper>
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public List<ApplicantExamPaper> queryByExamIdAndExamPaperId(String examId, String examPaperId) {
        Example example = new Example(ApplicantExamPaper.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("examId",examId);
        criteria.andEqualTo("examPaperId",examPaperId);
        criteria.andEqualTo("deleted",false);
        List<ApplicantExamPaper> applicantExamPapers = this.applicantExamPaperMapper.selectByExample(example);
        return applicantExamPapers;
    }


    /***
     * @Author lys(cherish)
     * @Phone 17720799636
     * @Date  2019/4/8
     * @Description 更新应聘让人试卷记录
     * @Param [examId, examPaperId, applicantId]
     * @Return java.lang.Integer
     * @Exception
     * @since JDK 1.8
     **/
    @Override
    public Integer noTxUpdataChecked(String examId, String examPaperId, String applicantId) {
        Example example = new Example(ApplicantExamPaper.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("examId",examId);
        criteria.andEqualTo("examPaperId",examPaperId);
        criteria.andEqualTo("applicantId",applicantId);
        criteria.andEqualTo("deleted",false);
        ApplicantExamPaper applicantExamPaper = new ApplicantExamPaper();
        applicantExamPaper.setChecked(1);
        return this.applicantExamPaperMapper.updateByExampleSelective(applicantExamPaper, example);
    }
}
